//
//  UIViewControllerExt.swift
//  covermedia

//  Created by travel on 16/2/23.
//  Copyright © 2016年 covermedia. All rights reserved.
//

import Foundation
import UIKit

public extension UIViewController {
    public func showAlertWithMessage(_ message: String?, block: ((Void) -> Void)?) {
        
        let alertController = UIAlertController(title: "", message: message, preferredStyle: .alert)
        let action: UIAlertAction = UIAlertAction(title: "确定", style: .default) { (_) -> Void in
            if let _ = block {
                block!()
            }
        }
        
        alertController.addAction(action)
        
        self.present(alertController, animated: true, completion: nil)
    }
    
    public func execute(_ step1: ((Void) -> Void)? ,seconds: Double ,afterthings: ((Void) -> Void)?) {
        
        if let _ = step1 {
            step1!()
        }
        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(2 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)) { () -> Void in
            if let _ = afterthings {
                afterthings!()
            }
        }
    }
    
    public class func someController<T: AnyObject>(_ vc: T.Type,ofStoryBoard storyBoard: String) -> T {
        let vc = UIStoryboard.init(name: storyBoard, bundle: nil).instantiateViewController(withIdentifier: String.init(describing: T.self)) as! T
        return vc
    }
}

public extension UIStoryboard {
    @nonobjc public static let main = "Main"
    @nonobjc public static let daily = "Daily"
    @nonobjc public static let Login = "Login"
}
